{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数字全排列\n",
    "\n",
    "[![Author](https://img.shields.io/badge/Author-%40mjd507-important?style=social&logo=GitHub)](https://github.com/mjd507)\n",
    "[![WeChat Channel](https://img.shields.io/badge/Wechat-Daily%20Problem-important?style=social&logo=WeChat)](https://mp.weixin.qq.com/s/Yki68qlxES96tNEYIfMC7w)\n",
    "\n",
    "![Logo](img/Day85-1.png)\n",
    "\n",
    "　　给定一个整数数组，返回其全排列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "def permute(nums: list) -> list:\n",
    "    if len(nums) == 1:\n",
    "        return [nums]\n",
    "    result = []\n",
    "    partion = permute(nums[1:])\n",
    "    for item in partion:\n",
    "        for i in range(len(nums)):\n",
    "            combine = item[:i] + [nums[0]] + item[i:]\n",
    "            result.append(combine)\n",
    "    return result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[1, 2, 3], [2, 1, 3], [2, 3, 1], [1, 3, 2], [3, 1, 2], [3, 2, 1]]\n"
     ]
    }
   ],
   "source": [
    "print(permute([1, 2, 3]))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
